using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;

public class Run_State : Ab_State
{
    [SerializeField] float speed = 2;

    private void OnEnable()
    {
        if (isStarted == false) return;
        body.velocity = new Vector3(player.transform.right.x * speed, body.velocity.y, 0);
    }
    protected override void Start()
    {
        base.Start(); 
        InputActions.Player.Jump.started += (context) =>
        {
            if (!this.gameObject.activeSelf) return;
            animator.SetTrigger("Jump");
        };

        //InputActions.Player.Move.started += Move;
        //InputActions.Player.Move.canceled += StopMove;
    }
    //void Move(InputAction.CallbackContext context)
    //{
    //    if (player.isMoving)
    //        animator.SetBool("Run", true);
    //}

    //void StopMove(InputAction.CallbackContext context)
    //{
    //    animator.SetBool("Run", false);
    //}


    private void FixedUpdate()
    {
        if (player.isMoving)
            body.velocity = new Vector3(player.transform.right.x * speed, body.velocity.y, 0);
        else
            animator.SetBool("Run", false);

        if (body.velocity.y * player.transform.up.y < -0.5f)
        {
            animator.SetTrigger("Fall");
        }
    }
}
